﻿Imports TBCC.Utility

''' <summary>
''' 压缩机组端口配置
''' </summary>
''' <remarks>
''' 只有并联机组存在端口配置
''' </remarks>
Public Class CcapCompressorSetPortItemService

    ''' <summary>
    ''' 默认构造函数
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub New()

    End Sub


    ''' <summary>
    ''' 查询压缩机组的端口
    ''' </summary>
    ''' <param name="csId">压缩机组端口号</param>
    ''' <returns>返回压缩机组口信息</returns>
    ''' <remarks>数据集包换字段：Id,csId,csSuckPressAlarmPort,csLowLiquidAlarmPort,csLowPowerAlarmPort</remarks>
    Public Function GetPorts(ByVal csId As Integer) As DataSet
        Dim ds As DataSet = Nothing
        Dim strSql As String = String.Empty

        strSql = " SELECT Id,csId,csSuckPressAlarmPort,csLowLiquidAlarmPort,csLostPowerAlarmPort " + _
                " FROM `tbccCompressorSetPortSet` WHERE `csId` =" + csId.ToString()

        Try
            ds = SqlHelper.ExecuteDataset(strSql, Nothing)
        Catch ex As Exception
            ds = Nothing
        End Try

        Return ds
    End Function


    ''' <summary>
    ''' 查询项目包含的冷凝机组及报警端口
    ''' </summary>
    ''' <param name="projectId">项目编号</param>
    ''' <returns> `Id`,csId,csNetId,csName,csSuckPressAlarmPort,csLowLiquidAlarmPort,CsLostPowerAlarmPort</returns>
    ''' <remarks></remarks>
    Function GetGroupNameAndPorts(ByVal ProjectId As String) As DataSet
        Dim ds As DataSet = Nothing
        Dim strSql As String = String.Empty

        strSql = " SELECT P.`Id`,P.csId,T.csNetId,D.csName,P.csSuckPressAlarmPort,P.csLowLiquidAlarmPort,P.CsLostPowerAlarmPort " & _
                " FROM tbcccompressorsetportset AS P Inner Join tbcccompressorset AS D ON P.csId = D.Id AND D.csType = 1 Inner Join tbccccapdevtype AS T ON D.DevId = T.Id " & _
                " WHERE(T.csNetId >= 50  And T.ProjectId = '" + ProjectId + "')"

        Try
            ds = SqlHelper.ExecuteDataset(strSql, Nothing)
        Catch ex As Exception
            ds = Nothing
        End Try

        Return ds
    End Function

    ''' <summary>
    ''' 更新并联机组端口
    ''' </summary>
    ''' <param name="Com"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function InsertCompressorSetPort(ByVal Com As CcapMultiCompressorSetPortItem) As Boolean
        Dim strSql As String
        Dim tic As New TBCC.Utility.TranstrationItem


        strSql = String.Format("delete from tbcccompressorsetportset where CsId='{0}'", Com.CsId)
        tic.Add(strSql, Nothing)
        strSql = "Insert into tbcccompressorsetportset(csId,csLostPowerAlarmPort,csSuckPressAlarmPort,csLowLiquidAlarmPort) Values(?p0,?p1,?p2,?p3)"

        Dim p1(3) As System.Data.Common.DbParameter

        p1(0) = New MySql.Data.MySqlClient.MySqlParameter()
        p1(0).ParameterName = "p0" : p1(0).Value = Com.CsId

        p1(1) = New MySql.Data.MySqlClient.MySqlParameter()
        p1(1).ParameterName = "p1" : p1(1).Value = Com.CsLostPowerAlarmPort

        p1(2) = New MySql.Data.MySqlClient.MySqlParameter()
        p1(2).ParameterName = "p2" : p1(2).Value = Com.CsSuckPressAlarmPort

        p1(3) = New MySql.Data.MySqlClient.MySqlParameter()
        p1(3).ParameterName = "p3" : p1(3).Value = Com.CsLowLiquidAlarmPort

        tic.Add(strSql, p1)


        Return TBCC.Utility.SqlHelper.ExecuteTranstration(tic)

    End Function
End Class
